package com.espirit.eap.sa;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.hibernate.annotations.BatchSize;

import com.espirit.eap.ICheckModelDuplicateInfo;
import com.espirit.eap.annotation.DomainModel;
import com.espirit.eap.annotation.ModelDisplayProperty;
import com.espirit.eap.pagelayout.AvabButton;
import com.googlecode.cswish.model.Saas;
import com.googlecode.cswish.security.auth.UserInfo;

@DomainModel
@Entity
@ModelDisplayProperty("code")
@BatchSize(size=10)
public class User implements UserInfo,ICheckModelDuplicateInfo, Saas {
	
	private static final long serialVersionUID = 6941368790239123213L;

	private LoginUser loginUser;
	
	// transient
	private String password1;
	private String password2;
	private User users;
	
	private Employee employee;
	
	private Integer sid;
	public Integer getSid() {
		return sid;
	}

	public void setSid(Integer sid) {
		this.sid = sid;
	}
	
	private Integer id;
	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	
	private String code;
	private String name;
	private String description;
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@ManyToOne(targetEntity = LoginUser.class, fetch=FetchType.EAGER, cascade=CascadeType.ALL)
	public LoginUser getLoginUser() {
		return loginUser;
	}

	public void setLoginUser(LoginUser loginUser) {
		this.loginUser = loginUser;
	}

	
	@Transient
	public String getPassword1() {
		return password1;
	}

	public void setPassword1(String password1) {
		this.password1 = password1;
	}
	
	@Transient
	public String getPassword2() {
		return password2;
	}

	public void setPassword2(String password2) {
		this.password2 = password2;
	}
	
	public void setUsers(User user){
		this.users = user;
	}
	@Transient
	public User getUsers(){
		return users;
	}
	
	public boolean permit(com.espirit.eap.pagelayout.Model model,AvabButton ab){
		return permit(model,ab.getName());
	}
	public boolean permit(com.espirit.eap.pagelayout.Model model,String buttonName){
		return false;
	}
	

	@Transient
	@Override
	public String getLoginId() {
		return String.valueOf(getId());
	}
	
	@Transient
	@Override
	public String[] getRoleIds() {
		return null;
	}

	private final static String[] gatherProperties = new String[]{"code"};
	@Override
	public String[] gatherProperties() {
		return gatherProperties;
	}
	

	@ManyToOne(fetch=FetchType.LAZY)
	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}
	
	private String deptIds;
	public String getDeptIds() {
		return deptIds;
	}

	public void setDeptIds(String departmentIds) {
		this.deptIds = departmentIds;
	}
	
	private String childDeptIds;
	private String childrenDeptIds;

	@Column(length=20000)
	public String getChildDeptIds() {
		return childDeptIds;
	}
	public void setChildDeptIds(String childIds) {
		this.childDeptIds = childIds;
	}
	
	@Column(length=20000)
	public String getChildrenDeptIds() {
		return childrenDeptIds;
	}
	public void setChildrenDeptIds(String childrenIds) {
		this.childrenDeptIds = childrenIds;
	}
	

}